/*
 * Copyright (C) 2013  Richard Schilling. All rights reserved.
 * contact: coderroadie@gmail.com
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package android.persist.op;

import java.util.Collection;

/**
 * {@code CreateStowage} is an empty marker class. Classes that initialize the
 * data store to persist classes of a given type extend this class.
 * 
 * @author Richard Schilling
 * @param <OT> the object type to setup a data store for.
 * @since 1.0
 */
public abstract class CreateStowage<OT> extends TrueFalseOperation<Class<OT>> {

    /**
     * Creates a new stowage operation, and checks to ensure that the operand is
     * an allowable class type.
     * 
     * @param operand the class type to create stowage for
     * @throws IllegalArgumentException if the type of class is not allowed to
     *             be persisted.
     */
    public CreateStowage(Class<OT> operand) {
        super(operand);

        boolean failCheck = false;
        String className = operand.getName();
        if (className.startsWith("android")) {
            failCheck = true;
        } else if (className.startsWith("java")) {
            failCheck = true;
        } else if (className.startsWith("dalvik")) {
            failCheck = true;
        } else if (className.startsWith("javax")) {
            failCheck = true;
        } else if (className.startsWith("junit")) {
            failCheck = true;
        } else if (className.startsWith("org.apache.http")) {
            failCheck = true;
        } else if (className.startsWith("org.json")) {
            failCheck = true;
        } else if (className.startsWith("org.wc3.dom")) {
            failCheck = true;
        } else if (className.startsWith("org.xml")) {
            failCheck = true;
        }

        /*
         * allow collection classes.
         */
        if (Collection.class.isAssignableFrom(operand)) {
            failCheck = false;
        }

        if (failCheck) {
            throw new IllegalArgumentException("persisting type " + className + " is not allowed");
        }

    }

}
